package controllers

import (
	"[[ .ModulePrefix ]]/internal/dto"
	"[[ .ModulePrefix ]]/internal/services"
	"[[ .ModulePrefix ]]/pkg/exports"
	"[[ .LogPack ]]"
	"github.com/gin-gonic/gin"
)

type [[ .ModelName ]]Ctl struct {
	BaseController
}

func New[[ .ModelName ]]Ctl() *[[ .ModelName ]]Ctl {
	return &[[ .ModelName ]]Ctl{}
}

func (p *[[ .ModelName ]]Ctl) Save(c *gin.Context) (interface{}, exports.APIError) {
	var param dto.[[ .ModelName ]]
	err := Bind(c, &param)
	if err != nil {
		return nil, err
	}
	rsp, err := services.Get[[ .ModelName ]]Svc().Save(c, &param)
	if err != nil {
		logging.Error(err).Send()
		return nil, err
	}
	return rsp, nil

}
func (p *[[ .ModelName ]]Ctl) FindAll(c *gin.Context) (interface{}, exports.APIError) {
	var param dto.[[ .ModelName ]]Param
	err := Bind(c, &param)
	if err != nil {
		return nil, err
	}
	rsp, err := services.Get[[ .ModelName ]]Svc().Find(c, param)
	if err != nil {
		logging.Error(err).Send()
		return nil, err
	}
	return rsp, nil
}
func (p *[[ .ModelName ]]Ctl) Delete(c *gin.Context) (interface{}, exports.APIError) {
	var param dto.[[ .ModelName ]]Id
	err := Bind(c, &param)
	if err != nil {
		return nil, err
	}
	rsp, err := services.Get[[ .ModelName ]]Svc().Delete(c, param)
		if err != nil {
		logging.Error(err).Send()
		return nil, err
	}
	return rsp, nil
}